package com.realtyManage.springboot.Dao;


import com.realtyManage.springboot.Model.Do.Comment;
import com.realtyManage.springboot.Model.Do.HouseDetail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface CommentRepository extends JpaRepository<Comment, Integer>, JpaSpecificationExecutor<Comment> {

   /* @Modifying
    @Transactional
    @Query("update HouseDetail a set " +
            "a.indoorArea = CASE WHEN :#{#houseDetail.indoorArea} IS NULL THEN a.indoorArea ELSE :#{#houseDetail.indoorArea} END ," +
            "a.blockCode = CASE WHEN :#{#houseDetail.blockCode} IS NULL THEN a.blockCode ELSE :#{#houseDetail.blockCode} END ," +
            "a.unitCode = CASE WHEN :#{#houseDetail.unitCode} IS NULL THEN a.unitCode ELSE :#{#houseDetail.unitCode} END ," +
            "a.doorplateCode = CASE WHEN :#{#houseDetail.doorplateCode} IS NULL THEN a.doorplateCode ELSE :#{#houseDetail.doorplateCode} END ," +
            "a.architectureArea = CASE WHEN :#{#houseDetail.architectureArea} IS NULL THEN a.architectureArea ELSE :#{#houseDetail.architectureArea} END ," +
            "a.face = CASE WHEN :#{#houseDetail.face} IS NULL THEN a.face ELSE :#{#houseDetail.face} END ," +
            "a.oldPrice = CASE WHEN :#{#houseDetail.oldPrice} IS NULL THEN a.oldPrice ELSE :#{#houseDetail.oldPrice} END ," +
            "a.oldTotal = CASE WHEN :#{#houseDetail.oldTotal} IS NULL THEN a.oldTotal ELSE :#{#houseDetail.oldTotal} END ," +
            "a.discountPrice = CASE WHEN :#{#houseDetail.discountPrice} IS NULL THEN a.discountPrice ELSE :#{#houseDetail.discountPrice} END ," +
            "a.discountTotal = CASE WHEN :#{#houseDetail.discountTotal} IS NULL THEN a.discountTotal ELSE :#{#houseDetail.discountTotal} END ," +
            "a.type = CASE WHEN :#{#houseDetail.type} IS NULL THEN a.type ELSE :#{#houseDetail.type} END ," +
            "a.special = CASE WHEN :#{#houseDetail.special} IS NULL THEN a.special ELSE :#{#houseDetail.special} END ," +
            "a.addUid = CASE WHEN :#{#houseDetail.addUid} IS NULL THEN a.addUid ELSE :#{#houseDetail.addUid} END ," +
            "a.addUserName = CASE WHEN :#{#houseDetail.addUserName} IS NULL THEN a.addUserName ELSE :#{#houseDetail.addUserName} END " +
            "where a.id = :#{#houseDetail.id}")
    int update(@Param("houseDetail") HouseDetail houseDetail);*/



    @Modifying
    @Transactional
    @Query(value = "delete from comment where id in(?1) ",nativeQuery = true)
    int deleteComment(List ids);

    @Modifying
    @Transactional
    @Query(value = "UPDATE comment set type  = 1 where id =?1",nativeQuery = true)
    int approvalComment(String id);

    @Query(value = "select * from comment where id =?1",nativeQuery = true)
    Comment getComment(Integer id);
}
